package com.example.xiaomi.Model.Dao;

import com.example.xiaomi.Model.entity.AddressEntity;
import com.example.xiaomi.Model.utils.BaseDB;
import com.example.xiaomi.Model.utils.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class AddressDao extends BaseDB {
    //id指定查询
    public List<AddressEntity> idspecify(int id){
        String sql = "SELECT uid,upostbox,aname,aphone,aprovince,acity,adistrict,label,astreet,adetail  FROM `is_ueser`,`is_address` where 1 <=> 1 and is_address.aid <=> is_ueser.uid and is_ueser.uid <=>"+id;
        return super.query(sql,new AddressRowMapper());
    }
    //邮箱指定
    public List<AddressEntity> mailspecify(String mail){
        String sql = "SELECT uid,upostbox,aname,aphone,aprovince,acity,adistrict,label,astreet,adetail  FROM `is_ueser`,`is_address` where 1 <=> 1 and is_address.aid <=> is_ueser.uid and is_ueser.upostbox <=> "+mail;
        return super.query(sql,new AddressRowMapper());
    }
    class AddressRowMapper implements RowMapper<AddressEntity> {
        @Override
        public AddressEntity rowmap(ResultSet rs) throws SQLException {
            return new AddressEntity(rs.getInt("uid"),
                                     rs.getString("upostbox"),
                                     rs.getString("aname"),
                                     rs.getString("aphone"),
                                     rs.getString("aprovince"),
                                     rs.getString("acity"),
                                     rs.getString("adistrict"),
                                     rs.getString("astreet"),
                                     rs.getString("adetail"),
                                     rs.getString("label"));
        }
    }
}
